package br.com.winesys.geta.report;

import java.awt.BorderLayout;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import javax.swing.JDialog;
import javax.swing.JPanel;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JRViewer;

public class CustomJasperViewer extends JDialog {

	private JPanel pnlMain;
	protected JRViewer viewer = null;

	public CustomJasperViewer(JasperPrint jasperPrint, Window owner) {
		super(owner);
		initComponents();
		setModal(true);
		setModalityType(ModalityType.APPLICATION_MODAL);
		this.viewer = new JRViewer(jasperPrint);
		this.pnlMain.add(this.viewer, BorderLayout.CENTER);
	}

	private void initComponents() {
		this.pnlMain = new javax.swing.JPanel();
		setTitle("JasperViewer");
		setIconImage(new javax.swing.ImageIcon(getClass().getResource("/net/sf/jasperreports/view/images/jricon.GIF")).getImage());
		addWindowListener(new java.awt.event.WindowAdapter() {

			@Override
			public void windowClosing(java.awt.event.WindowEvent evt) {
				exitForm();
			}
		});

		this.pnlMain.setLayout(new java.awt.BorderLayout());

		getContentPane().add(this.pnlMain, java.awt.BorderLayout.CENTER);
		this.setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
	}

	void exitForm() {
		this.setVisible(false);
		this.viewer.clear();
		this.viewer = null;
		this.getContentPane().removeAll();
		this.dispose();
	}

	public void setZoomRatio(float zoomRatio) {
		this.viewer.setZoomRatio(zoomRatio);
	}

	public void setFitWidthZoomRatio() {
		this.viewer.setFitWidthZoomRatio();
	}

	public void setFitPageZoomRatio() {
		this.viewer.setFitPageZoomRatio();
	}
}
